package org.kukker.animation;

import org.kukker.activity.widget.FloatingMenu;



import android.util.Log;
import android.view.View;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.AbsoluteLayout;
import android.widget.LinearLayout.LayoutParams;

public class AnimationFactory {
		private static AnimationFactory instance;

		public static AnimationFactory getInstance() {
			if (AnimationFactory.instance == null) {
				AnimationFactory.instance = new AnimationFactory();
			}
			return AnimationFactory.instance;

		}
		
		
		
		
		public TranslateAnimation getFloatingMenuVisibleAnimation() {
			long animationDuration = 500;

			TranslateAnimation translateAnim;
			translateAnim = new TranslateAnimation(-100, 0, 0, 0);
			translateAnim.setDuration(animationDuration);

			FloatingMenuVisibleAnimationListener mal = new FloatingMenuVisibleAnimationListener();
			translateAnim.setAnimationListener(mal);
			return translateAnim;
		}

		public TranslateAnimation getFloatingMenuInvisibleAnimation() {
			long animationDuration = 500;

			TranslateAnimation translateAnim;
			translateAnim = new TranslateAnimation(0, -100, 0, 0);
			translateAnim.setDuration(animationDuration);

			FloatingMenuInvisibleAnimationListener mal = new FloatingMenuInvisibleAnimationListener();
			translateAnim.setAnimationListener(mal);
			return translateAnim;
		}

		class FloatingMenuVisibleAnimationListener implements AnimationListener {
			@Override
			public void onAnimationEnd() {
				Log.i("EventView", "AnimationEnd");
				
				AbsoluteLayout.LayoutParams abslp = new AbsoluteLayout.LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
						100, 100);
				FloatingMenu.getInstance().setLayoutParams(abslp);
			}

			@Override
			public void onAnimationRepeat() {
				// TODO Auto-generated method stub
			}

			@Override
			public void onAnimationStart() {
				// TODO Auto-generated method stub
				AbsoluteLayout.LayoutParams abslp = new AbsoluteLayout.LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
						0, 100);
				FloatingMenu.getInstance().setLayoutParams(abslp);
				
				FloatingMenu.getInstance().setVisibility(View.VISIBLE);
				FloatingMenu.getInstance().showChildren();
			}
		}
		
		
		class FloatingMenuInvisibleAnimationListener implements AnimationListener {
			@Override
			public void onAnimationEnd() {
				Log.i("EventView", "AnimationEnd");
				AbsoluteLayout.LayoutParams abslp = new AbsoluteLayout.LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
						0, 100);
				FloatingMenu.getInstance().setLayoutParams(abslp);
				FloatingMenu.getInstance().setVisibility(View.GONE);
				FloatingMenu.getInstance().hideChildren();
				
				
			}

			@Override
			public void onAnimationRepeat() {
				// TODO Auto-generated method stub
			}

			@Override
			public void onAnimationStart() {
				FloatingMenu.getInstance().setVisibility(View.VISIBLE);
				// TODO Auto-generated method stub
			}
		}

	}




		
